package com.example.shop.user.vo;

import com.example.shop.common.api.ResponseResult;
import com.example.shop.pojo.UserAddressBook;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class LinkmanInfo {
    /**
     * 联系人id
     */
    private Long linkmanId;
    /**
     * 联系人的头像
     */
    private String linkmanPicture;
    /**
     * 联系人的名字
     */
    private String linkmanName;
    /**
     * 联系人电话
     */
    private String linkmanPhone;
    /**
     * 联系人地区
     */
    private String linkmanArea;
    /**
     * 联系人详细地址
     */
    private String detailedAddress;


    public LinkmanInfo setLinkmanPicture(String linkmanPicture) {
        this.linkmanPicture = ResponseResult.toRequestPath(linkmanPicture);
        return this;
    }

    /**
     * 根据地址簿信息获取该联系人的信息
     * @param userAddressBook 地址簿
     * @return 返回联系人信息
     */
    public static LinkmanInfo getLinkmanInfo(UserAddressBook userAddressBook){
        LinkmanInfo linkmanInfo = new LinkmanInfo();
        linkmanInfo.setLinkmanId(userAddressBook.getLinkmanId())
                .setLinkmanPicture(userAddressBook.getLinkmanPicture())
                .setLinkmanName(userAddressBook.getLinkmanName())
                .setLinkmanArea(userAddressBook.getLinkmanArea())
                .setLinkmanPhone(userAddressBook.getLinkmanPhone())
                .setDetailedAddress(userAddressBook.getDetailedAddress());
        return linkmanInfo;
    }


    @Override
    public String toString() {
        return "LinkmanInfo{" +
                "linkmanId=" + linkmanId +
                ", linkmanName='" + linkmanName + '\'' +
                ", linkmanPhone='" + linkmanPhone + '\'' +
                ", linkmanArea='" + linkmanArea + '\'' +
                ", detailedAddress='" + detailedAddress + '\'' +
                '}';
    }
}
